# /**
# * Copyright (c) 2022 Beijing Jiaotong University
# * photlab is licensed under [Open Source License].
# * You can use this software according to the terms and conditions of the [Open Source License].
# *
# * You may obtain a copy of [Open Source License] at: [https://open.source.license/]
# *
# * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# *
# * See the [Open Source License] for more details.
# */
# /**
# * Author: Shihao Xie
# * Created: Mar. 18, 2022
# * Supported by: National Key Research and Development Program of China
# */
# interface count = 37
namespace py phot_server.rpc.device_service

include "common_data_type.thrift"
include "device_data_type.thrift"

service Device{

    device_data_type.PhotGrid init_grid(1:double x, 2:double y, 3:double z, 4:double permittivity, 5:double permeability,
                                        6:double wave_length, 7:i32 step, 8:i32 time, 9:i32 pml_x, 10:i32 pml_y, 11:i32 pml_z
                                        12:string material,)
    // grid management
    device_data_type.PhotGrid open_grid(1:string grid_path) throws (1:common_data_type.PhotError error)

    device_data_type.PhotGrid close_grid(1:i32 grid_id) throws (1:common_data_type.PhotError error)

    void save_grid(1:i32 grid_id) throws (1:common_data_type.PhotError error)

    void save_grid_as(1:i32 grid_id, 2:string file_path) throws (1:common_data_type.PhotError error)

    map<string, string> get_opened_grid_list() throws (1:common_data_type.PhotError error)

    // Add services
    device_data_type.PhotGrid add_grid(1:device_data_type.PhotGrid grid) throws (1:common_data_type.PhotError error)

    device_data_type.PhotSource add_source(1:i32 grid_id, 2:device_data_type.PhotSource source) throws (1:common_data_type.PhotError error)

    device_data_type.PhotWaveguide add_waveguide(1:i32 grid_id, 2:device_data_type.PhotWaveguide waveguide) throws (1:common_data_type.PhotError error)

    device_data_type.PhotMaterial add_material(1:device_data_type.PhotMaterial material) throws (1:common_data_type.PhotError error)

    device_data_type.PhotDetector add_detector(1:i32 grid_id, 2:device_data_type.PhotDetector detector) throws (1:common_data_type.PhotError error)

    // Get services
    device_data_type.PhotGrid get_grid(1:i32 grid_id) throws (1:common_data_type.PhotError error)

    device_data_type.PhotSource get_source(1:i32 grid_id, 2:i32 source_id) throws (1:common_data_type.PhotError error)

    device_data_type.PhotWaveguide get_waveguide(1:i32 grid_id, 2:i32 waveguide_id) throws (1:common_data_type.PhotError error)

    device_data_type.PhotMaterial get_material(1:string material_name) throws (1:common_data_type.PhotError error)

    list<device_data_type.PhotMaterial> get_materials() throws (1:common_data_type.PhotError error)

    list<string> get_material_name_list() throws (1:common_data_type.PhotError error)

    device_data_type.PhotDetector get_detector(1:i32 grid_id, 2:i32 detector_id)
                                               throws (1:common_data_type.PhotError error)

    device_data_type.PhotFigure get_figure(1:i32 grid_id, 2:string axis, 3:i32 axis_index=-1, 4:string figure_type) throws (1:common_data_type.PhotError error)

    map<string, device_data_type.PhotFigure> get_figures(1:i32 grid_id, 2:list<i32> axis_index=[-1,-1,-1], 3:string figure_type) throws (1:common_data_type.PhotError error)

    string get_waveguide_default_parameter_list(1:string name) throws (1:common_data_type.PhotError error)

    string get_all_waveguide_default_parameter_list() throws (1:common_data_type.PhotError error)

    // Update services
    void update_grid(1:device_data_type.PhotGrid grid) throws (1:common_data_type.PhotError error)

    void update_source(1:i32 grid_id, 2:device_data_type.PhotSource source)
                             throws (1:common_data_type.PhotError error)

    void update_waveguide(1:i32 grid_id, 2:device_data_type.PhotWaveguide waveguide)
                          throws (1:common_data_type.PhotError error)

    void update_material(1:device_data_type.PhotMaterial material)
                         throws (1:common_data_type.PhotError error)

    // TODO:更新PhotMaterialProperty的接口
    void update_material_property(1:string material_name,2:device_data_type.PhotMaterialProperty property) throws (1:common_data_type.PhotError error)
    // TODO: 更新监视器
    void update_detector(1:i32 grid_id, 2:device_data_type.PhotDetector detector) throws (1:common_data_type.PhotError error)

    // Delete services
    void delete_grid(1:i32 grid_id) throws (1:common_data_type.PhotError error)

    void delete_source(1:i32 grid_id, 2:i32 source_id) throws (1:common_data_type.PhotError error)

    void delete_waveguide(1:i32 grid_id, 2:i32 waveguide_id) throws (1:common_data_type.PhotError error)

    void delete_material(1:string material_name) throws (1:common_data_type.PhotError error)

    void delete_material_property(1:string material_name, 2:i32 property_id) throws (1:common_data_type.PhotError error)

    void delete_detector(1:i32 grid_id,2:i32 detector_id) throws (1:common_data_type.PhotError error)

    // Save services
    void save_material_as(1:string material_name, 2:string file_path) throws (1:common_data_type.PhotError error)

    void save_figure_as(1:i32 grid_id, 2:string axis, 3:list<i32> axis_index=[-1], 4:string file_path, 5:string figure_type) throws (1:common_data_type.PhotError error)

    list<device_data_type.PhotFigure> get_grid_figure_history(1:i32 grid_id) throws (1:common_data_type.PhotError error)

    # 让fdtd grid 进行仿真, 获取图像前需要进行这一步，且需要等这一步完成
    oneway void run(1:i32 grid_id)

    map<string, string> calculate_mode(1:i32 grid_id, 2:double lam = 1.55, 3:double neff = 3.47, 4:i32 neigs = 1,
                        5:string x_boundary_low="pml", 6:string y_boundary_low="pml", 7:i32 x_thickness_low=0,
                        8:i32 y_thickness_low=0, 9:string x_boundary_high="zero", 10:string y_boundary_high="zero",
                        11:i32 x_thickness_high=0, 12:i32 y_thickness_high=0)

    device_data_type.PhotFigure get_mode_figure(1:i32 grid_id, 2:string axis, 3:i32 axis_index, 4:double lam = 1.55, 5:double neff = 3.47, 6:i32 neigs = 1)

//    device_data_type.PhotFigure get_TEfraction_figure(1:i32 grid_id, 2:i32 n_levels = 6)
//
//    device_data_type.PhotFigure sweep(1:i32 grid_id, 2:i32 steps = 5, 3:list<i32> lams = [])
}